package org.jfab.core.model;

import org.jfab.core.adapter.Adapter;
import org.jfab.core.adapter.AdapterInjector;
import org.jfab.core.adapter.DefaultAdapterInjector;

/**
 * Provides a default model injector.
 */
public class DefaultModelInjector implements ModelInjector
{
    /** Adapter injector. */
    private final AdapterInjector _adapterInjector;

    /**
     * Construct this object.
     */
    public DefaultModelInjector()
    {
        this(new DefaultAdapterInjector());
    }

    /**
     * Construct this object with the given parameter.
     * 
     * @param adapterInjector Adapter injector.
     */
    public DefaultModelInjector(final AdapterInjector adapterInjector)
    {
        _adapterInjector = adapterInjector;
    }

    @Override
    public CGTypeUtilities injectCGTypeUtilities()
    {
        return new CGTypeUtilities(injectTypeFactory(), injectCGTypeAdapter());
    }

    @Override
    public TypeFactory injectTypeFactory()
    {
        return new DefaultTypeFactory();
    }

    /**
     * @return the adapterInjector
     */
    private AdapterInjector getAdapterInjector()
    {
        return _adapterInjector;
    }

    /**
     * @return a new type adapter.
     */
    private Adapter<CGType> injectCGTypeAdapter()
    {
        return getAdapterInjector().injectCGTypeAdapter();
    }
}
